import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @author xukai
 * @desc
 * @date 2017-02-10-下午 2:51
 */
public class syc extends Thread{

        int b=100;

        public synchronized void m1(){

            try{
                Thread.sleep(10000);
                b=1000;
            }catch(Exception e){
                e.printStackTrace();
            }
            System.out.println("b="+b);
        }

        public  void m2(){



//            System.out.println(b);
            try{
                Thread.sleep(2000);
            }catch(Exception e){
                e.printStackTrace();
            }
            synchronized(new Object()) {
                b=2000;
        }
        }

        public void run(){
            try{
                m1();
            }catch(Exception e){
                e.printStackTrace();
            }
        }

        public static void main(String args[]) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
//            ArrayList<Integer> list = new ArrayList<Integer>();
//            Class<? extends ArrayList> aClass = list.getClass();
//            Method[] methods = aClass.getMethods();
//            for(Method method : methods){
////                System.out.println(method.getName() + method.getParameterTypes()[0]);
//            }
//            Method add = aClass.getMethod("add", Object.class);
//            add.invoke(list,122);
//            System.out.println(list.size());
//            syc syc = new syc();
            try {
                FileInputStream inputStream = new FileInputStream("E:\\java\\程序猿\\java\\book\\shoppingcart.data");
                DataInputStream stream = new DataInputStream(inputStream);
                double value = -1;
                while ((value = stream.readDouble()) != -1 ){
                    System.out.println("================" + new DecimalFormat("#").format(value));
                    System.out.println(stream.readInt());
                    System.out.println(stream.readUTF());
                    System.out.println(stream.available());
                }
                Object list = Arrays.asList("1", "2", "3");
                List<String> list1 = (List<String>) list;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }

    private static String hexStr =  "0123456789ABCDEF";
    /**
     *
     * @param bytes
     * @return 将二进制转换为十六进制字符输出
     */
    public static String BinaryToHexString(byte[] bytes){

        String result = "";
        String hex = "";
        for(int i=0;i<bytes.length;i++){
            //字节高4位
            hex = String.valueOf(hexStr.charAt((bytes[i]&0xF0)>>4));
            //字节低4位
            hex += String.valueOf(hexStr.charAt(bytes[i]&0x0F));
            result +=hex+" ";
        }
        return result;
    }


}
